package sve;

public class Converter {

	public static double[] toDouble(String[] s) {
		double[] d = new double[s.length];
		int i = 0;
		for (String ss : s) {
			if (ss != null && ss.length() > 0)
				d[i++] = Double.parseDouble(ss);
			else
				d[i++] = 0;
		}

		return d;
	}

	public static String[] toString(double[] d) {
		String[] s = new String[d.length];
		int i = 0;
		for (double dd : d) {
			s[i++] = Double.toString(dd);
		}

		return s;
	}

	public static String[][] toString(double[][] d) {
		String[][] s = new String[d.length][d[0].length];
		int i = 0;
		for (double[] dd : d) {
			s[i++] = toString(dd);
		}

		return s;
	}

	public static String toString(double[][] d, String seperator, String lineSep) {
		StringBuilder s = new StringBuilder();
		for (int i = 0; i < d.length; i++) {
			for (int j = 0; j < d[i].length; j++) {
				s.append(d[i][j]);
				if (j < d[i].length - 1)
					s.append(seperator);
			}
			if (i < d.length - 1)
				s.append(lineSep);
		}
		return s.toString();
	}

	public static String toString(double[][][] d, String seperator, String lineSep) {
		StringBuilder s = new StringBuilder();
		for (int i = 0; i < d.length; i++) {
			for (int j = 0; j < d[i].length; j++) {
				for (int k = 0; k < d[i][j].length; k++) {
					s.append(d[i][j][k]);
					if (k < d[i][j].length - 1)
						s.append(seperator);
				}
				if (j < d[i].length - 1)
					s.append(lineSep);
			}
			if (i < d.length - 1)
				s.append(lineSep);
		}
		return s.toString();
	}

	private static String toString(double[] d, String seperator) {
		StringBuilder s = new StringBuilder();

		for (int i = 0; i < d.length; i++) {
			s.append(d[i]);
			if (i < d.length - 1)
				s.append(seperator);
		}

		return s.toString();
	}
}
